package com.ecelin.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ecelin.entity.CityInfo;
import com.ecelin.service.CityInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/city")
@RequiredArgsConstructor
public class CityInfoController {

    private final CityInfoService cityInfoService;

    @GetMapping
    public List<CityInfo> getBookInfo(){
        List<CityInfo> list = cityInfoService.list();
        return list;
    }


    @PostMapping("add")
    public CityInfo add(@RequestBody CityInfo cityInfo){
        cityInfo.setId(IdWorker.getIdStr(CityInfo.class));
        cityInfoService.save(cityInfo);
        return cityInfo;
    }

}
